package compiler;

import genericObject.GenericObject;
import house.House;

import java.util.ArrayList;

import pointAndLine.Point;
import room.Room;
import sensor.Sensor;
import wall.Wall;

public class Compiler {
	public static ArrayList<Point> allPoints=new ArrayList<Point>();
	public static ArrayList<Wall> allWalls=new ArrayList<Wall>();
	public static ArrayList<Room> allRooms=new ArrayList<Room>();
	static ArrayList<GenericObject> allObjects=new ArrayList<GenericObject>();
	static ArrayList<Sensor> allSensors=new ArrayList<Sensor>();
	public static House myHouse=new House();
	static boolean haveHouse=false;
	static Create pointCreator=new CreatePoint();
	static Create wallCreator=new CreateWall();
	static Create roomCreator=new CreateRoom();
	static Create objectCreator=new CreateObject();
	static Create sensorCreator=new CreateSensor();
	static Create houseCreator=new CreateHouse();
		
		public Compiler(){}
		
		public static boolean executeCommand(String command)
		{
			boolean result=false;
			ArrayList<String> commandBreakdown=LineParser.parseLine(command);

			if ( commandBreakdown.get(0).equalsIgnoreCase("Create") ){
				if( commandBreakdown.get(1).equalsIgnoreCase("Point") )
				{
					commandBreakdown.remove(0);
					commandBreakdown.remove(0);
					allPoints.add((Point) pointCreator.ExecutCommand(commandBreakdown));
				}//done
				if( commandBreakdown.get(1).equalsIgnoreCase("Wall") )
				{
					commandBreakdown.remove(0);
					commandBreakdown.remove(0);
					allWalls.add((Wall) wallCreator.ExecutCommand(commandBreakdown));
				}//done
				if( commandBreakdown.get(1).equalsIgnoreCase("Room") )
				{
					commandBreakdown.remove(0);
					commandBreakdown.remove(0);
					allRooms.add((Room) roomCreator.ExecutCommand(commandBreakdown));
				}//done
				if( commandBreakdown.get(1).equalsIgnoreCase("Object") )
				{
					commandBreakdown.remove(0);
					commandBreakdown.remove(0);
					allObjects.add((GenericObject) objectCreator.ExecutCommand(commandBreakdown));
				}//done
				if( commandBreakdown.get(1).equalsIgnoreCase("Sensor") )
				{
					commandBreakdown.remove(0);
					commandBreakdown.remove(0);

					allSensors.add((Sensor) sensorCreator.ExecutCommand(commandBreakdown));
				}//needs sensor class				
				if( commandBreakdown.get(1).equalsIgnoreCase("House") )
				{
					commandBreakdown.remove(0);
					commandBreakdown.remove(0);
					myHouse=(House)houseCreator.ExecutCommand(commandBreakdown);
				}
			}
			
			return result;
		}
}
